package pingji.controller.query;

import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pingji.controller.query.ResultObject.Pingji;
import pingji.controller.query.ResultObject.QueryPingjiObject;
import pingji.controller.query.ResultObject.QueryUserObject;
import pingji.dao.mapper.UserMapper;
import pingji.pojo.User;
import pingji.service.query.QueryUserService;
import pingji.service.query.UserService;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@Log
public class QueryUserController {
    @Autowired
    QueryUserService service;
    @RequestMapping("/query")
    public QueryUserObject query(@RequestParam("id") Integer id){
        if(id==null){
            return null;
        }
        QueryUserObject o=new QueryUserObject();
        UserService query = service.query(id);
        o.setName(query.getName());
        o.setId(query.getId());
        o.setIsVIP(query.getIsVIP());
        log.info(o.toString());
        return o;
    }

    @RequestMapping("/all_pingjier")
    public QueryPingjiObject all_pingjier(){
        List<User> list = mapper.selectAllPingjier();
        QueryPingjiObject qpo=new QueryPingjiObject();
        qpo.setCount(list.size());
        for(User u:list){
            Pingji p=new Pingji();
            log.info(u.toString());
            p.setId(u.getId());
            p.setName(u.getName());
            qpo.getList().add(p);
        }
        return qpo;
    }
    @Autowired
    UserMapper mapper;
}
